<template>
	<view class="">
		<map-Point ref="mappoint" @commitCheck="commitCheck" :mapKey='mapKey' :Radius='Radius'
			:showResetting='showResetting' :listIco='listIco' :orientationIco='orientationIco'
			:resettingIco='resettingIco' :configData='configData'></map-Point>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				mapKey: '4b8ea5adcd58017a7dbcbf43f6131efb',
				address: '',
				latitude: '',
				longitude: '',
				listIco: '/uni_modules/map-Point/static/item-inx.png',
				orientationIco: '/uni_modules/map-Point/static/map-inx.png',
				resettingIco: "/uni_modules/map-Point/static/position.png",
				showResetting: true,
				Radius: '',
				// 微信公众号jsSdk配置
				configData: {
					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: '', // 必填，公众号的唯一标识
					timestamp: '', // 必填，生成签名的时间戳
					nonceStr: '', // 必填，生成签名的随机串
					signature: '', // 必填，签名
				},
			};
		},
		onShow() {
			this.$nextTick(() => {
				this.$refs.mappoint.getInfo()
			})
		},
		methods: {
			commitCheck(e) {
				let that = this
				uni.showLoading({
					mask: true,
					title:"Loading"
				})
				httpRequest.request('/api/v1/userAddress/existUser', 'GET', {
					lng: e.longitude,
					lat: e.latitude,
				}).then(res => {
					if (res.code == 200) {
						if (res.data.existStatus) {
							uni.hideLoading()
							httpRequest.toast("当前区域已被他人标记，请滑动地图切换位置")
							return false
						} else {
							this.submit(e)
						}
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			submit(e) {
				httpRequest.request('/api/v1/userAddress/add', 'POST', {
					longitude: e.longitude,
					latitude: e.latitude,
				}).then(res => {
					uni.hideLoading()
					console.log("选择地址", res);
					if (res.code == 200) {
						if (e.type == 1) {
							uni.navigateTo({
								url: "/pages/index/perfectInformation"
							})
						} else {
							this.$refs.mappoint.getInfo()
						}
					}
				})
			}
		}
	};
</script>